package zhihuilan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import zhihuilan.entity.MyFactoryFav;
import zhihuilan.entity.MyGoods;
import zhihuilan.mapper.MyFactoryFavMapper;
import zhihuilan.mapper.MyGoodsMapper;
import zhihuilan.service.MyGoodsService;

import java.util.List;

@Service
public class MyGoodsServiceImpl extends ServiceImpl<MyGoodsMapper, MyGoods> implements MyGoodsService {

    @Override
    public List<MyGoods> selectList(Integer type, Integer category,Integer status) {
        if (ObjectUtils.isEmpty(type) && ObjectUtils.isEmpty(category)) {
            return null;
        }
        QueryWrapper<MyGoods> wrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(type)) {
            wrapper.eq("type", type);
        }
        if (!ObjectUtils.isEmpty(category)) {
            wrapper.eq("category", category);
        }
        wrapper.orderByAsc("sort");
        return this.baseMapper.selectList(wrapper);
    }

    @Override
    public MyGoods selectGoodsInfoById(Integer id) {
        if(ObjectUtils.isEmpty(id)){
            return null;
        }
        MyGoods entity = this.baseMapper.selectById(id);
        if(ObjectUtils.isEmpty(entity)){
            return null;
        }
        if(!entity.getStatus().equals(1)){
            return null;
        }
        return entity;
    }
}
